﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StatusPlan3
{
    public class Companies : List<Company> { }
    public class Company
    {
        public int id { get; set; }
        public String companyName { get; set; }

        public Contacts contacts { get; set; }

        public Company()
        {
            contacts = new Contacts();
        }
    }

    public class Contacts : List<Contact> { }
    public class Contact
    {
        public int id { get; set; }
        public String firstName { get; set; }
        public String lastName { get; set; }
        public String phone { get; set; }
        public String mobile { get; set; }
        public String email { get; set; }
    }

    public class AttachedFiles : List<AttachedFile> 
    {
        public Decimal getTotalSize()
        {
            Decimal size = 0;

            foreach(AttachedFile af in this) 
            {
                size += af.size;
            }

            return size;
        }

        public int getTotalNumberOfFiles()
        {
            int size = 0;

            foreach (AttachedFile af in this)
            {
                size += af.countFiles;
            }

            return size;
        }

    }
    public class AttachedFile
    {
        public int id { get; set; }
        public String fileName { get; set; }
        public String fileType { get; set; }
        public DateTime dateAdded { get; set; }
        public User createdBy { get; set; }
        public Boolean isFolder { get; set; }
        public AttachedFile folder { get; set; }
        public int? folderID { get; set; }
        public int countFiles
        {
            get
            {
                if (isFolder)
                    return attachedFiles.getTotalNumberOfFiles();
                else
                    return 1;
            }
        }

        private Decimal _size;

        public Decimal size { 
            get 
            {
                if (isFolder)
                    return attachedFiles.getTotalSize();
                else
                    return _size;
            }
            set 
            { 
                _size = value; 
            }
        }

        public AttachedFiles attachedFiles { get; set; }
        public String path { get; set; }


        public AttachedFile()
        {
            attachedFiles = new AttachedFiles();
        }
    }

    public class Issues : List<Issue> { }
    public class Issue
    {
        public int id { get; set; }
        public User createdBy { get; set; }
        public DateTime createdDate { get; set; }
        public User responsible { get; set; }
        public String name { get; set; }
        public String description { get; set; }
        public DateTime? startDate { get; set; }
        public DateTime? endDate { get; set; }
        public DateTime? planedEndDate { get; set; }
        public DateTime? deadline { get; set; }
        public Decimal? estimatedHours { get; set; }
        public Decimal? usedHours { get; set; }
        public Decimal? progress { get; set; }
        public Decimal? addedEstimatedHours { get; set; }
        public Company fromCompany { get; set; }
        public IssueType issueType { get; set; }
        public IssueStatus issueStatus { get; set; }
        public Priority priority { get; set; }

        public AttachedFiles attachedFiles { get; set; }
        public Messages messages { get; set; }
        public IssueLogs logs { get; set; }

        public String projectName { get; set; }

        public Issue()
        {
            attachedFiles = new AttachedFiles();
            messages = new Messages();
            logs = new IssueLogs();
        }
    }

    public class IssueStatuses : List<IssueStatus> { }
    public class IssueStatus
    {
        public int id { get; set; }
        public String name { get; set; }
        public Boolean canEdit { get; set; }
    }

    public class IssueTypes : List<IssueType> { }
    public class IssueType
    {
        public int id { get; set; }
        public String name { get; set; }
    }

    public class IssueLogs : List<IssueLog> { }
    public class IssueLog
    {
        public int id { get; set; }
        public String body { get; set; }
        public DateTime createdDate { get; set; }
    }

    public class ProjectLogs : List<ProjectLog> { }
    public class ProjectLog
    {
        public int id { get; set; }
        public String body { get; set; }
        public DateTime createdDate { get; set; }
    }

    public class ProjectGroupLogs : List<ProjectGroupLog> { }
    public class ProjectGroupLog
    {
        public int id { get; set; }
        public String body { get; set; }
        public DateTime createdDate { get; set; }
    }

    public class SubprojectLogs : List<SubprojectLog> { }
    public class SubprojectLog
    {
        public int id { get; set; }
        public String body { get; set; }
        public DateTime createdDate { get; set; }
    }

    public class TaskLogs : List<TaskLog> { }
    public class TaskLog
    {
        public int id { get; set; }
        public String body { get; set; }
        public DateTime createdDate { get; set; }
    }

    public class Messages : List<Message> { }
    public class Message
    {
        public int id { get; set; }
        public String subject { get; set; }
        public String message { get; set; }
        public DateTime createdDate { get; set; }
        public User sender { get; set; }

        public AttachedFiles attachedFiles { get; set; }
        public Messages replies { get; set; }

        public Message()
        {
            attachedFiles = new AttachedFiles();
            replies = new Messages();
        }
    }

    public class Priorities : List<Priority> { }
    public class Priority
    {
        public int id { get; set; }
        public String name { get; set; }
        public int priorityIndex { get; set; }
    }

    public class Projects : List<Project> { }
    public class Project
    {
        public int id { get; set; }
        public String name { get; set; }
        public DateTime? startDate { get; set; }
        public DateTime? endDate { get; set; }
        public DateTime createdDate { get; set; }
        public DateTime? deadline { get; set; }
        public Decimal? estimatedTime { get; set; }
        public User createdBy { get; set; }
        public User responsible { get; set; }

        public AttachedFiles attachedFiles { get; set; }
        public Messages messages { get; set; }
        public Subprojects subproject { get; set; }
        public Tasks tasks { get; set; }
        public Issues issues { get; set; }
        public ProjectLogs logs { get; set; }

        public Project()
        {
            attachedFiles = new AttachedFiles();
            messages = new Messages();
            subproject = new Subprojects();
            tasks = new Tasks();
            issues = new Issues();
            logs = new ProjectLogs();
        }
    }

    public class ProjectGroups : List<ProjectGroup> { }
    public class ProjectGroup
    {
        public int id { get; set; }
        public String name { get; set; }
        public DateTime? startDate { get; set; }
        public DateTime? endDate { get; set; }
        public DateTime? planedEndDate { get; set; }
        public DateTime createdDate { get; set; }
        public Boolean isActive { get; set; }
        public User createdBy { get; set; }

        public Projects projects { get; set; }
        public IssueTypes issueTypes { get; set; }
        public IssueStatuses issueStatuses { get; set; }
        public Priorities priorities { get; set; }
        public Statuses statuses { get; set; }
        public Types types { get; set; }
        public Users projectMembers { get; set; }
        public ProjectGroupLogs logs { get; set; }

        public ProjectGroup()
        {
            projects = new Projects();
            issueTypes = new IssueTypes();
            issueStatuses = new IssueStatuses();
            priorities = new Priorities();
            statuses = new Statuses();
            types = new Types();
            projectMembers = new Users();
            logs = new ProjectGroupLogs();
        }
    }

    public class Roles : List<Role> { }
    public class Role
    {
        public int id { get; set; }
        public String name { get; set; }
    }

    public class Statuses : List<Status> { }
    public class Status
    {
        public int id { get; set; }
        public String name { get; set; }
        public Boolean isEditable { get; set; }
    }

    public class Subprojects : List<Subproject> { }
    public class Subproject
    {
        public int id { get; set; }
        public String name { get; set; }
        public DateTime? startDate { get; set; }
        public DateTime? endDate { get; set; }
        public DateTime? plannedEndDate { get; set; }
        public DateTime? createdDate { get; set; }
        public Decimal? estimatedTime { get; set; }
        public User createdBy { get; set; }
        public User responsible { get; set; }

        public AttachedFiles attachedFiles { get; set; }
        public Messages messages{ get; set; }
        public Tasks tasks { get; set; }
        public Issues issues { get; set; }
        public SubprojectLogs logs { get; set; }

        public Subproject()
        {
            attachedFiles = new AttachedFiles();
            messages = new Messages();
            tasks = new Tasks();
            issues = new Issues();
            logs = new SubprojectLogs();
        }
    }

    public class Tasks : List<Task> { }
    public class Task
    {
        public int id { get; set; }
        public Priority priority { get; set; }
        public Type type { get; set; }
        public Status status { get; set; }
        public DateTime createdDate { get; set; }
        public User createdBy { get; set; }
        public User responsible { get; set; }
        public String name { get; set; }
        public String description { get; set; }
        public DateTime? startedDate { get; set; }
        public DateTime? plannedEndDate { get; set; }
        public DateTime? endDate { get; set; }
        public Decimal? estimatedTime { get; set; }
        public Decimal? timeUsed { get; set; }
        public DateTime? deadline { get; set; }
        public Decimal? progress { get; set; }
        public Decimal? addedEstimatedHours { get; set; }
        public Task parent { get; set; }
        public int? parentID { get; set; }



        public Decimal? remainingTime { get { if (estimatedTime != null && timeUsed != null) return estimatedTime.Value - timeUsed.Value; else return null; } }
        public String subprojectName { get; set; }

        public Messages messages { get; set; }
        public AttachedFiles attachedFiles { get; set; }
        public Issues taskIssues { get; set; }
        public TaskLogs logs { get; set; }
        public Tasks decendants { get; set; }

        public String projectName { get; set; }

        public Task()
        {
            messages = new Messages();
            attachedFiles = new AttachedFiles();
            taskIssues = new Issues();
            logs = new TaskLogs();
            decendants = new Tasks();
        }
    }

    public class Types : List<Type> { }
    public class Type
    {
        public int id { get; set; }
        public String name { get; set; }
    }

    public class UserStandard
    {
        public int id { get; set; }
        public int? projectGroup_id { get; set; }
        public int? project_id { get; set; }
    }

    public class Users : List<User> { }
    public class User
    {
        public int id { get; set; }
        public String userName { get; set; }
        public String password { get; set; }
        public Boolean changePassword { get; set; }
        public DateTime? lastChangedPassword { get; set; }
        public String windowsLogin { get; set; }
        public String firstName { get; set; }
        public String lastName { get; set; }
        public String fullName { get { String fullName = firstName; if (lastName != null) fullName += " " + lastName; return fullName; } }
        public String email { get; set; }
        public Roles roles { get; set; }

        public UserStandard userStandard { get; set; }

        public String rolesString
        {
            get
            {
                if (roles.Count == 0)
                {
                    return "";
                }
                else
                {
                    String roleString2 = "";
                    foreach (Role r in roles)
                    {
                        if (roleString2.Length > 0)
                            roleString2 += ",";

                        roleString2 += r.name;
                    }
                    return roleString2;
                }
            }
        }
        public User()
        {
            roles = new Roles();
        }
    }
}
